package codeine.servlets;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import codeine.PeerInDirectoryRegistrator;

import com.google.inject.Inject;

public class PeerUpdateDirectoryServlet extends HttpServlet
{
	private static final Logger log = Logger.getLogger(PeerUpdateDirectoryServlet.class);
	private static final long serialVersionUID = 1L;
	@Inject	private PeerInDirectoryRegistrator peerInDirectoryRegistrator;
	
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
	{
		try {
			log.info("PeerUpdateDirectoryServlet started");
			peerInDirectoryRegistrator.register();
			res.getWriter().write("registered peer in directory at " + new Date());
		} catch (Exception e) {
			log.warn("fail in servlet", e);
		}
	}
}
